#include "Food.h"

Food::Food(const QPixmap &pixmap, QPoint xy){
	partWidth = 20;
	this->pix = pix;
	this->xy = QPoint(xy.x()*partWidth, xy.y()*partWidth);//xy*QPoint(20,20);
}

Food::Food() {
	partWidth = 20;
	pix = QPixmap(":/food");
}

Food::Food(QString pos) {
	partWidth = 20;
	pix = QPixmap(":/food");
	QStringList list = pos.split(",");
	setXY(QPoint(list[0].toInt(), list[1].toInt()));
}

QRectF Food::boundingRect() const {
	qreal adjust = 0.5;
	return QRectF(0-adjust, 0-adjust, 20+adjust, 20+adjust);
}

QPainterPath Food::shape(){
	QPainterPath path;
	path.addRect(boundingRect());
	return path;
}

void Food::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {

	Q_UNUSED(widget);
	Q_UNUSED(option);

	painter->drawPixmap(xy, pix);
}

QPixmap Food::getPart() {
	return pix;
}

void Food::setPart(const QPixmap &pix) {
	this->pix = pix;
}

QPoint Food::getXY() {
	return QPoint(xy.x()/partWidth, xy.y()/partWidth);//xy / QPoint(20,20);
}

QPoint Food::getRealXY() {
	return xy;
}

void Food::setXY(const QPoint xy) {
	this->xy = QPoint(xy.x()*partWidth, xy.y()*partWidth);
}

void Food::randomXY(int maxX, int maxY) {
	xy = QPoint((qrand()%maxX)*partWidth, (qrand()%maxY)*partWidth);
}



